package models

import (
	"iptv_server/v3/src/models/homevideo_model"
	"iptv_server/v3/src/source_manager"
	"iptv_server/v3/src/utils"
)

type v3api struct{}

func RegisterSources() {
	source_manager.Register("homeVide", new(v3api), true)
}

func (vv *v3api) GetHome(id string) (any, error) {
	i := utils.ParseInter(id, 1)
	return homevideo_model.GetHome(i)
}

func (vv *v3api) GetPage(id string, limit string, page string) (any, error) {
	i := utils.ParseInter(id, 1)
	lim := utils.ParseInter(limit, 15)
	pg := utils.ParseInter(page, 1)
	ret, err := homevideo_model.GetPage(i, lim, pg)
	if err != nil {
		return ret, err
	}
	return convertDetails(ret)

}

func (vv *v3api) GetDetail(id string) (any, error) {
	i := utils.ParseInter(id, 1)
	detail, err := homevideo_model.GetDetail(i)
	if err != nil {
		return detail, err
	}
	return convertDetailPlayListToString(detail)
}

func (vv *v3api) GetPlay(id string) (any, error) {
	i := utils.ParseInter(id, 1)
	p, err := homevideo_model.GetPlay(i)
	if err != nil {
		return p, err
	}
	return convertPlay(p)
}
